<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑栏目</title>
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
</head>
<body>
<form class="layui-form" id="cat_add_form" style="padding: 10px 20px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">栏目名</label>
        <div class="layui-input-block"><input type="text" class="layui-input" name="cat_name" placeholder="请输入栏目名">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">父级栏目</label>
        <div class="layui-input-block">
            <select name="parent_id">
                <option value="0">设为一级栏目</option>
                {foreach name="cat_list" item="v"}
                <option value="{$v.id}">{$v.cat_name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block"><input type="number" class="layui-input" name="order" placeholder="数值越小越靠前">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示</label>
        <div class="layui-input-block">
            <input type="hidden" name="is_show" value="0">
            <input type="checkbox" name="is_show" value="1" lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">介绍</label>
        <div class="layui-input-block">
            <textarea class="layui-textarea" name="content" id="editor" placeholder="请输入栏目介绍"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" onclick="catAdd()">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
</html>
<script src="__STATIC__/layui/layui.all.js"></script>
<script src="__STATIC__/js/common.js"></script>
<script>
    let index;
    let layedit;
    layui.use('layedit', function () {
        layedit = layui.layedit;
        index = layedit.build('editor', {
            tool: ['strong' //加粗
                , 'italic' //斜体
                , 'underline' //下划线
                , 'del' //删除线
                , '|' //分割线
                , 'left' //左对齐
                , 'center' //居中对齐
                , 'right' //右对齐
                , 'link' //超链接
                , 'unlink' //清除链接
                , 'face' //表情
            ]
        }); //建立编辑器
    });

    function catAdd() {
        document.getElementById('editor').innerText = layedit.getContent(index);
        let res = ajaxSubmit(document.getElementById('cat_add_form'), '{:url("cat/catAdd",["_ajax"=>1])}', 'post');
        if (res) {
            closeOpen(1500);
        }
    }
</script>